//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package com.eternizedlab.airquality;

import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.google.android.apps.dashclock.api.DashClockExtension;
import com.google.android.apps.dashclock.api.ExtensionData;

public class AirQualityExtension extends DashClockExtension {
  private static final String TAG = AirQualityExtension.class.getSimpleName();

  public static final String PREF_SHORTCUT = "pref_shortcut";

  private static final Intent BUILTIN_CALENDAR_INTENT = new Intent(
      Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
          Intent.CATEGORY_APP_CALENDAR))
      .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  @Override
  protected void onUpdateData(int reason) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    Intent clickIntent = AppChooserPreference.getIntentValue(
        sp.getString(PREF_SHORTCUT, null), BUILTIN_CALENDAR_INTENT);

    publishUpdate(new ExtensionData().visible(true)
        .icon(R.drawable.ic_launcher).status("300")
        .expandedTitle("Good. PM2.5 300")
        .expandedBody("PM2.5 100, PM10 300, SO2 14").clickIntent(clickIntent));
  }

  @Override
  protected void onInitialize(boolean isReconnect) {
    super.onInitialize(isReconnect);
    setUpdateWhenScreenOn(true);
  }

}
